package pl.edu.pw.polygen.modeler.client.workspace.listener;

import pl.edu.pw.polygen.modeler.client.object.IPolygenObject;
import pl.edu.pw.polygen.modeler.client.object.Segment;
import pl.edu.pw.polygen.modeler.client.object.Splain;
import pl.edu.pw.polygen.modeler.client.object.Vertex;
import pl.edu.pw.polygen.modeler.client.workspace.IWorkspace;

import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseWheelEvent;

/**
 * @author borysfan
 * @14-01-2012 @10:30:54
 */
public class SplainListener extends BaseWorkspaceListener {

	private IWorkspace workspace;
	private IPolygenObject polygenObject = null;
	
	public SplainListener(IWorkspace workspace) {
		this.workspace = workspace;
	}
	
	@Override
	public void onMouseDown(MouseDownEvent event) {
		if(polygenObject==null){
			if(workspace.getSelected()!=null){
				Vertex beginVertex = (Vertex) workspace.getSelected();
				this.polygenObject = new Splain(beginVertex, event.getX(), event.getY(), workspace);
			}else{
				polygenObject = new Splain(event.getX(), event.getY(),event.getX(),event.getY(),workspace);
			}
			polygenObject.add();
		}
	}

	@Override
	public void onMouseUp(MouseUpEvent event) {
		polygenObject.initialize();
		polygenObject.remove();
		polygenObject.add();
		polygenObject.drop();
		polygenObject = null;
		workspace.unselectAll();
	}

}
